package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestControllerAdvice
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理", tags = "channel", description = "频道管理API")
public class AdChannelController {
    @Autowired
    AdChannelService adChannelService;

    /**
     *      查  频道
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(adChannelService.getById(id));
    }
    @PostMapping("/list")
    @ApiOperation(value = "频道列表分页查询",tags = "根据分页查询频道信息")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDTO channelDTO){
        return adChannelService.findByNameAndPage(channelDTO);
    }

    @PostMapping("save")
    public ResponseResult addChannel(@RequestBody AdChannel adChannel){
        return adChannelService.addChannel(adChannel);
    }
    @PostMapping("update")
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel){
        return adChannelService.updateChannel(adChannel);

    }
    @GetMapping("del/{id}")
    public ResponseResult deleteChannel(@PathVariable("id") Integer id){
        return adChannelService.deleteChannel(id);
    }

    @GetMapping("channels")
    public ResponseResult findAllChannels(){
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
